﻿@{
    ViewData["Title"] = "EditPassword";
}
<form class="layui-form layui-form-pane" lay-filter="">
    <div class="layui-form-item">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-block">
            <input type="password" name="oldPsw" autocomplete="off" class="layui-input" lay-verify="required|pass" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">新密码</label>
        <div class="layui-input-block">
            <input type="password" name="newPsw" autocomplete="off" class="layui-input" lay-verify="required|pass" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" name="confirmNewPsw" autocomplete="off" class="layui-input" lay-verify="required|pass|confirmPass" />
        </div>
    </div>
    <div class="layui-form-item" style="text-align:center;">
        <button class="layui-btn" lay-submit lay-filter="save">保存</button>
        <button class="layui-btn" id="cancel">取消</button>
    </div>
</form>

@section Scripts
{
<script type="text/javascript">
    layui.use(function() {
        var form = layui.form;
        var $ = layui.jquery;
        form.verify({
          confirmPass: function(value){
            if(value !== $('input[name=newPsw]').val()){
              return "两次密码输入不一致";
            }
          }
          ,pass: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
          ]
        });
        form.on("submit(save)", function(formdata) {
            $.ajax({
                url: '/SysUser/EditPassword',
                data: {
                    oldPsw: formdata.field.oldPsw,
                    newPsw: formdata.field.newPsw
                },
                success: function(res) {
                    if (res.Code == 200) {
                        layer.msg('修改成功', {
                            time: 1000
                        }, function() {
                            parent.layer.closeAll('iframe');
                        });
                    } else {
                        layer.msg(res.Message);
                    }
                }
            });
            return false;
        })
        $("#cancel").click(function() {
            parent.layer.closeAll();
            return false;
        })
    })
</script>
}